import { BadRequestException, Controller, Get, Query } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthDto } from './auth.dto';

@Controller()
export class AuthController {

  constructor(private authService: AuthService) {
  }

  @Get()
  auth(@Query() query: AuthDto) {
    const { signature, timestamp, nonce, echostr } = query;
    if (this.authService.validate(signature, [timestamp, nonce])) {
      return echostr;
    }
    throw new BadRequestException();
  }

}
